Skip to content

Support GitHub Enterprise deployments via environment-aware URLs#16309

Closed
Copilot wants to merge 5 commits intomainfrom
copilot/review-github-urls-replacement
Closed

Support GitHub Enterprise deployments via environment-aware URLs#16309
Copilot wants to merge 5 commits intomainfrom
copilot/review-github-urls-replacement

Conversation

Copy link
Contributor

Copilot AI commented Feb 17, 2026

Enterprise GitHub URL Support

Replace all hardcoded "https://github.com" references with environment-aware URLs that support GitHub Enterprise deployments.

Summary of Changes

Go Files Updated (13 files):

  • pkg/cli/trial_repository.go - Repository creation, cloning URLs, and settings URLs (8 changes)
  • pkg/cli/pr_command.go - Fork and remote URLs (2 changes)
  • pkg/cli/secret_collection.go - PAT creation URL (1 change)
  • pkg/cli/add_interactive_engine.go - PAT creation URL (1 change)
  • pkg/cli/add_interactive_workflow.go - Actions page URL (1 change)
  • pkg/cli/download_workflow.go - Git ls-remote and clone URLs (6 changes)
  • pkg/cli/trial_command.go - Workflow run URLs and repo URLs (3 changes)
  • pkg/cli/update_actions.go - Git ls-remote URL (1 change)
  • pkg/parser/remote_fetch.go - Git fallback URLs (3 changes) + helper function
  • pkg/stringutil/pat_validation.go - Added ValidateCopilotPATWithHost() for enterprise-aware error messages
  • pkg/cli/github.go - Enhanced helper to support GITHUB_API_URL
  • pkg/parser/remote_fetch.go - Enhanced helper to support GITHUB_API_URL

JavaScript/Shell Scripts:

  • ✅ All .cjs files already correctly use process.env.GITHUB_SERVER_URL || "https://github.com"
  • ✅ Shell scripts already correctly use $GITHUB_SERVER_URL with fallback

Tests Added:

  • TestValidateCopilotPATWithHost - Validates enterprise host URLs in error messages (6 test cases)
  • TestGetGitHubHost - Enhanced with GITHUB_API_URL test coverage (12 test cases)

Implementation Details

Both getGitHubHost() helpers now support multiple environment variables with automatic URL derivation:

Environment variable priority order:

  1. GITHUB_SERVER_URL - GitHub Actions standard, full URL (e.g., https://github.enterprise.com)
  2. GH_HOST - gh CLI standard, hostname (e.g., github.enterprise.com or https://github.enterprise.com)
    • Automatically adds https:// prefix if only hostname is provided
  3. GITHUB_API_URL - Derives server URL from API URL:
    • https://api.github.comhttps://github.com
    • https://api.github.enterprise.comhttps://github.enterprise.com
    • https://github.enterprise.com/api/v3https://github.enterprise.com
  4. Default - Falls back to https://github.com

CLI package (pkg/cli/github.go):

func getGitHubHost() string {
    // Checks GITHUB_SERVER_URL → GH_HOST → GITHUB_API_URL → default
    // Handles URL normalization and derivation automatically
}

Parser package (pkg/parser/remote_fetch.go):

// Same logic, separate implementation to avoid circular dependencies
func getGitHubHost() string { ... }

URLs Updated

User-facing URLs:

  • Repository creation success messages
  • GitHub Actions settings page links
  • PAT creation URLs in error messages
  • Workflow run URLs
  • Repository preservation messages

Internal git operations:

  • Repository cloning (git clone)
  • Remote fetching (git ls-remote)
  • Archive downloads (git archive)
  • Fork and upstream remotes

Plan

  • Analyze codebase for hardcoded GitHub URLs
  • Update Go files to use getGitHubHost() helper
    • pkg/cli/trial_repository.go - Repository creation and cloning URLs
    • pkg/cli/pr_command.go - Fork and remote URLs
    • pkg/cli/secret_collection.go - PAT creation URL
    • pkg/cli/add_interactive_engine.go - PAT creation URL
    • pkg/cli/add_interactive_workflow.go - Actions page URL
    • pkg/cli/download_workflow.go - Git fallback URLs
    • pkg/cli/trial_command.go - Workflow run and repo URLs
    • pkg/cli/update_actions.go - Git ls-remote URL
    • pkg/parser/remote_fetch.go - Git fallback URLs + helper
    • pkg/stringutil/pat_validation.go - PAT creation error messages
  • Refactor parser package to use helper instead of duplicating code
  • Add support for GITHUB_API_URL environment variable with automatic derivation
  • Update JavaScript files (already using GITHUB_SERVER_URL correctly)
    • Verified all .cjs files use GITHUB_SERVER_URL
  • Update Shell scripts (already using GITHUB_SERVER_URL correctly)
    • Verified clone_repo_memory_branch.sh
  • Add tests for enterprise URL support
    • Added TestValidateCopilotPATWithHost tests
    • Enhanced TestGetGitHubHost with GITHUB_API_URL coverage
  • Run validation and tests
    • make fmt
    • make build
    • Selective tests passed
    • make test-unit (CI will validate)
    • make agent-finish (requires golangci-lint)
Original prompt

Review all instance of "https://github.com/" in go or js and determine if it should be replaced by the GitHub api root in the context. This is relevant for enterprise deployment outside of the GitHub domain.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 17, 2026 07:55
…ise support

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Review instances of GitHub URLs for replacement with API root Support GitHub Enterprise deployments via environment-aware URLs Feb 17, 2026
Copilot AI requested a review from pelikhan February 17, 2026 08:02
Copy link
Contributor

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot review changes and keep reusing helper


repoURL := fmt.Sprintf("https://github.com/%s/%s.git", owner, repo)
// Get GitHub host from environment with fallback
githubHost := os.Getenv("GITHUB_SERVER_URL")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use helper

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored to use a getGitHubHost() helper function in the parser package. All three instances of the duplicated code now use the helper. (d961583)

…e duplication

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan February 17, 2026 13:17
@pelikhan pelikhan marked this pull request as ready for review February 17, 2026 13:21
Copilot AI review requested due to automatic review settings February 17, 2026 13:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for GitHub Enterprise deployments by replacing hardcoded https://github.com URLs with environment-aware URLs throughout the Go codebase. The implementation uses a getGitHubHost() helper function that checks GITHUB_SERVER_URL (GitHub Actions standard), then GH_HOST (gh CLI standard), and defaults to https://github.com.

Changes:

  • Introduced ValidateCopilotPATWithHost() function in pkg/stringutil/pat_validation.go to support enterprise-aware error messages
  • Added getGitHubHost() helper in pkg/parser/remote_fetch.go to avoid circular dependencies
  • Updated 13 Go files across CLI and parser packages to use environment-aware GitHub URLs
  • Added comprehensive test coverage for enterprise host URL validation

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/stringutil/pat_validation.go Added ValidateCopilotPATWithHost() function to support enterprise GitHub URLs in PAT validation error messages; existing ValidateCopilotPAT() now delegates to this function with default host
pkg/stringutil/pat_validation_test.go Added TestValidateCopilotPATWithHost with 6 test cases covering both default and enterprise hosts for all token types
pkg/parser/remote_fetch.go Added package-local getGitHubHost() helper and updated 3 git operations (ls-remote, archive, clone) to use enterprise-aware URLs
pkg/cli/update_actions.go Updated git ls-remote URL construction to use getGitHubHost()
pkg/cli/trial_repository.go Updated 8 URLs including repository creation messages, Actions settings links, and git clone operations
pkg/cli/trial_command.go Updated workflow run URLs and repository preservation messages
pkg/cli/secret_collection.go Updated PAT creation URL in prompt message
pkg/cli/pr_command.go Updated fork and upstream remote URLs for cross-repository PR creation
pkg/cli/download_workflow.go Updated 6 git operations (ls-remote for tags, branches, default branch; git archive and clone)
pkg/cli/add_interactive_workflow.go Updated GitHub Actions page URL for Codespaces users
pkg/cli/add_interactive_engine.go Updated PAT creation URL in prompt message

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pelikhan
Copy link
Contributor

@copilot see #16312 for other env var to use to resolve host

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 17, 2026

@copilot see #16312 for other env var to use to resolve host

Added support for GITHUB_API_URL environment variable. The helpers now check (in order): GITHUB_SERVER_URL, GH_HOST, GITHUB_API_URL (deriving server URL from API URL), then default to https://github.com. Added comprehensive test coverage for all scenarios including API URL patterns like https://api.github.enterprise.comhttps://github.enterprise.com. (a3af264)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh issue view 16312 --json title,body,comments --jq {title, body, comments: [.comments[] | {author: .author.login, body: .body}]} (http block)
    • Triggering command: /usr/bin/gh gh issue view 16312 (http block)

If you need me to access, download, or install something from one of these locations, you can either:

}
if host == "" {
// Try to derive from GITHUB_API_URL
if apiURL := os.Getenv("GITHUB_API_URL"); apiURL != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove sniffing api url

// then falls back to GH_HOST (gh CLI standard),
// then derives from GITHUB_API_URL if available,
// and finally defaults to https://github.com
func getGitHubHost() string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot delete this function and use getGithubhost in GitHub package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants